﻿using System.ServiceModel;
using System.Data.SqlClient;
using System.Data;
namespace BLL.SystemMan
{
    [ServiceContract]
    public class SMerchandise
    {
        DAL.DALMethod myDAL = new DAL.DALMethod();

        /// <summary>
        /// （下拉框）商品类别
        /// </summary>
        /// <returns></returns>
        [OperationContract]
        public DataSet SelectCate()
        {
            SqlParameter[] sql =
            {
                new SqlParameter ("@type",SqlDbType.VarChar),
            };
            sql[0].Value = "SelectProductCategory";
            DataSet ds = myDAL.QueryDataSet("SMerchandise", sql);
            return ds;
        }

        /// <summary>
        /// （下拉框）单位
        /// </summary>
        /// <returns></returns>
        [OperationContract]
        public DataSet SelectUnit()
        {
            SqlParameter[] sql =
            {
                new SqlParameter ("@type",SqlDbType.VarChar),
            };
            sql[0].Value = "SelectCommoditiesUnit";
            DataSet ds = myDAL.QueryDataSet("SMerchandise", sql);
            return ds;
        }

        /// <summary>
        /// 查询
        /// </summary>
        /// <returns></returns>
        [OperationContract]
        public DataSet CheckSMerchandise()
        {
            //声明参数数组对象
            SqlParameter[] sqls =
            {
                //实例化数组对象，查询无条件使用@type，有条件再添加其他的@
                new SqlParameter("@type",SqlDbType.VarChar)
            };
            //数组元素赋值
            sqls[0].Value = "SelectSMerchandise";//存储语句名称
            //调用数据层查询方法
            DataSet ds = myDAL.QueryDataSet("SMerchandise", sqls);
            return ds;
        }
        
        /// <summary>
        /// 新增
        /// </summary>
        /// <param name="intProductCategoryID"></param>
        /// <param name="intCommoditiesUnitID"></param>
        /// <param name="StrProductCode"></param>
        /// <param name="StrProductName"></param>
        /// <param name="blDisable"></param>
        /// <param name="blNoGifts"></param>
        /// <param name="StrSpecifications"></param>
        /// <param name="StrColor"></param>
        /// <returns></returns>
        [OperationContract]
        public int InsertManage(int intProductCategoryID,int intCommoditiesUnitID,
           string StrProductCode,string StrProductName,bool blDisable,bool blNoGifts, 
           string StrSpecifications,string StrColor)
        {
            //实例化对象数组
            SqlParameter[] sql =
           {
                new SqlParameter("@type",SqlDbType.VarChar),
                new SqlParameter("@productCategoryID",SqlDbType.Int),
                new SqlParameter("@commoditiesUnitID",SqlDbType.Int),
                new SqlParameter("@productCode",SqlDbType.NVarChar),
                new SqlParameter("@productName",SqlDbType.NVarChar),
                new SqlParameter("@remark",SqlDbType.NVarChar),
                new SqlParameter("@disable",SqlDbType.Bit),
                new SqlParameter("@noGifts",SqlDbType.Bit),
                new SqlParameter("@specifications",SqlDbType.NVarChar),
                new SqlParameter("@color",SqlDbType.NVarChar)
            };
            sql[0].Value = "NewSupplier";
            sql[1].Value = intProductCategoryID;//商品类别
            sql[2].Value = intCommoditiesUnitID;//单位
            sql[3].Value = StrProductCode;//商品编码
            sql[4].Value = StrProductName;//商品名称
            sql[5].Value = blDisable;//禁用
            sql[6].Value = blNoGifts;//赠品
            sql[7].Value = StrSpecifications;//规格型号
            sql[8].Value = StrColor;//颜色
            //调用数据层新增方法
            int intCount = myDAL.UpdateData("SMerchandise", sql);
            //返回受影响行数
            return intCount;
        }

        /// <summary>
        /// 修改
        /// </summary>
        /// <param name="intProductCategoryID"></param>
        /// <param name="intCommoditiesUnitID"></param>
        /// <param name="StrProductCode"></param>
        /// <param name="StrProductName"></param>
        /// <param name="blDisable"></param>
        /// <param name="blNoGifts"></param>
        /// <param name="StrSpecifications"></param>
        /// <param name="StrColor"></param>
        /// <param name="intProductID"></param>
        /// <returns></returns>
        [OperationContract]
        public int UpdateStaff(int intProductCategoryID, int intCommoditiesUnitID,
           string StrProductCode, string StrProductName, bool blDisable, bool blNoGifts,
           string StrSpecifications, string StrColor,int intProductID)
        {
            //实例化对象数组
            SqlParameter[] sql =
           {
                new SqlParameter("@type",SqlDbType.VarChar),
                new SqlParameter("@productCategoryID",SqlDbType.Int),
                new SqlParameter("@commoditiesUnitID",SqlDbType.Int),
                new SqlParameter("@productCode",SqlDbType.NVarChar),
                new SqlParameter("@productName",SqlDbType.NVarChar),
                new SqlParameter("@remark",SqlDbType.NVarChar),
                new SqlParameter("@disable",SqlDbType.Bit),
                new SqlParameter("@noGifts",SqlDbType.Bit),
                new SqlParameter("@specifications",SqlDbType.NVarChar),
                new SqlParameter("@color",SqlDbType.NVarChar),
                new SqlParameter("@productID",SqlDbType.Int)
            };
            sql[0].Value = "NewSupplier";
            sql[1].Value = intProductCategoryID;//商品类别
            sql[2].Value = intCommoditiesUnitID;//单位
            sql[3].Value = StrProductCode;//商品编码
            sql[4].Value = StrProductName;//商品名称
            sql[5].Value = blDisable;//禁用
            sql[6].Value = blNoGifts;//赠品
            sql[7].Value = StrSpecifications;//规格型号
            sql[8].Value = StrColor;//颜色
            sql[9].Value = intProductID;
            //调用数据层新增方法
            int intCount = myDAL.UpdateData("SMerchandise", sql);
            //返回受影响行数
            return intCount;
        }
        /// <summary>
        /// 删除
        /// </summary>
        /// <param name="intProductID"></param>
        /// <returns></returns>
        [OperationContract]
        public int DelectStaff(int intProductID)
        {
            SqlParameter[] SQLCMDpas ={
                                          new  SqlParameter ("@type",SqlDbType.VarChar),
                                          new  SqlParameter ("@productID",SqlDbType.Int),
                                                  };
            SQLCMDpas[0].Value = "DeleteSupplier";
            SQLCMDpas[1].Value = intProductID;
            int count = myDAL.UpdateData("SMerchandise", SQLCMDpas);
            return count;
        }
        /// <summary>
        /// 禁用
        /// </summary>
        /// <param name="blDisable"></param>
        /// <param name="intProductID"></param>
        /// <returns></returns>
        [OperationContract]
        public int DisaNo(bool blDisable, int intProductID)
        {
            SqlParameter[] sql ={
                                          new  SqlParameter ("@type",SqlDbType.VarChar),
                                          new  SqlParameter ("@disable",SqlDbType.Bit),
                                          new  SqlParameter ("@productID",SqlDbType.Int),
                                              };
            sql[0].Value = "StopOrNotLine";
            sql[1].Value = blDisable;
            sql[2].Value = intProductID;
            int count = myDAL.UpdateData("SMerchandise", sql);
            return count;
        }
        /// <summary>
        /// 赠品
        /// </summary>
        /// <param name="blNoGifts"></param>
        /// <param name="intProductID"></param>
        /// <returns></returns>
        [OperationContract]
        public int Gifts(bool blNoGifts, int intProductID)
        {
            SqlParameter[] sql ={
                                          new  SqlParameter ("@type",SqlDbType.VarChar),
                                          new  SqlParameter ("@noGifts",SqlDbType.Bit),
                                          new  SqlParameter ("@productID",SqlDbType.Int),
                                              };
            sql[0].Value = "StopOrNotLine";
            sql[1].Value = blNoGifts;
            sql[2].Value = intProductID;
            int count = myDAL.UpdateData("SMerchandise", sql);
            return count;
        }
    }
}
